package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.dto.SysRegisterDTO;
import com.nineclock.system.dto.SysUserDTO;
import com.nineclock.system.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
@Api(value = "用户管理接口",tags = "系统服务")
public class SysUserController {

    @Autowired
    private SysUserService userService;
    /**
     * 根据手机号/用户名查询用户
     */
    @GetMapping("query")
    @ApiOperation("根据手机号/用户名查询用户")
    public Result<SysUserDTO> queryUser(@RequestParam String username){
        SysUserDTO sysUserDTO = userService.queryUser(username);
        return Result.success(sysUserDTO);
    }

    /**
     * 用户注册: 注册用户
     * 接口路径：POST/sys/user/register
     */
    @ApiOperation(value = "注册用户")
    @PostMapping("register")
    public Result register(SysRegisterDTO registerDTO){
        userService.register(registerDTO);
        return Result.success();
    }

}
